﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using phudieuhungthinh.DAL;

namespace phudieuhungthinh.BL.Model
{
    public class CategoryMenu
    {
        public CategoryMenu(Category category, IEnumerable<Category> subCategories)
        {
            Name = category.Name;
            Url = category.Url;
            ID = category.ID;

            if (subCategories != null)
            {
                SubMenus = (from x in subCategories
                            where x.ParentId == category.ID
                            select new CategoryMenu(x, subCategories)).ToList();
            }
        }
        public CategoryMenu(Category category, IEnumerable<Category> subCategories, int productId)
        {
            Name = category.Name;
            Url = category.Url;
            ID = category.ID;
            ProductCategoriesImpl impl = new ProductCategoriesImpl();
            var productCategories = impl.GetProductCategories(productId);
            foreach (var item in productCategories)
            {
                if (item.CategoryID == ID)
                {
                    Checked = true;
                }
            }

            if (subCategories != null)
            {
                SubMenus = (from x in subCategories
                            where x.ParentId == category.ID
                            select new CategoryMenu(x, subCategories, productId)).ToList();
            }
        }
        public CategoryMenu(int cateId, Category category, IEnumerable<Category> subCategories)
        {
            Name = category.Name;
            Url = category.Url;
            ID = category.ID;
            Checked = cateId == ID;
            
            if (subCategories != null)
            {
                SubMenus = (from x in subCategories
                            where x.ParentId == category.ID
                            select new CategoryMenu(cateId, x, subCategories)).ToList();
            }
        }

        public int ID { get; set; }
        public string Name { get; set; }
        public string Url { get; set; }
        public IList<CategoryMenu> SubMenus { get; set; }
        public bool Checked { get; set; }
    }
}
